package com.bbex.mapper;

import com.bbex.entity.CoinAddress;
import com.bbex.vo.AddressVO;
import com.bbex.sql.build.CoinAddressSqlBuild;
import org.apache.ibatis.annotations.*;

import java.sql.Timestamp;
import java.util.List;

@Mapper
public interface CoinAddressDao {

    @Select("select id,address,user_id as userId,coin_id as coinId,symbol,type,status,create_date as createDate,update_date as updateDate " +
            "from js_plat_coin_address where coin_id = #{coinId} and user_id = '0' and status = 0 limit 1")
    CoinAddress findByCoinId(String coinId);

    @UpdateProvider(type = CoinAddressSqlBuild.class, method = "updateById")
    Long updateById(CoinAddress coinAddress);

    @Update("update js_plat_coin_address set user_id = #{userId}, status = #{status} where id = #{id} and update_date = #{updateDate}")
    long updateUserIdAndStatusByIdAndUpdateDate(@Param("userId") String userId, @Param("status") int i, @Param("id") String id, @Param("updateDate") Timestamp updateDate);

    @Update("update js_plat_coin_address set user_id = #{userId}, status = #{status}, hid = #{hid} where id = #{id} and update_date = #{updateDate}")
    long updateUserIdAndStatusByHidAndUpdateDate(@Param("userId") String userId, @Param("status") int i, @Param("id") String id, @Param("updateDate") Timestamp updateDate, @Param("hid") String hid);

    @InsertProvider(type = CoinAddressSqlBuild.class, method = "batchInsert")
    void batchInsert(@Param("listValues") List<CoinAddress> list);

    @InsertProvider(type = CoinAddressSqlBuild.class, method = "insert")
    void insert(CoinAddress coinAddress);

    @Select("select " + CoinAddressSqlBuild.columns + " from js_plat_coin_address where address = #{address} limit 1")
    CoinAddress findByAddress(String address);

    @Select("select " + CoinAddressSqlBuild.columns + " from js_plat_coin_address where type = #{type}")
    List<CoinAddress> findByType(Integer type);

    @Select("select address from js_plat_coin_address where symbol = #{symbol}")
    List<AddressVO> findAddressBySymbol(String symbol);

}
